package personal.xjl._23java1studentdemo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import personal.xjl._23java1studentdemo.mapper.StudentMapper;
import personal.xjl._23java1studentdemo.model.Student;
import personal.xjl._23java1studentdemo.service.StudentService;

import java.util.List;

@Service    //类似于@Controller@Mapper,告诉spring容器帮忙创建一个service对象
public class StudentServiceImpl implements StudentService {
    @Autowired
    StudentMapper studentMapper;
    @Override
    public List<Student> findAll() {
        return studentMapper.selectAll();
    }

    @Override
    public int remove(int id) {
        return studentMapper.delete(id);
    }

    @Override
    public int add(Student student) {
        return studentMapper.insert(student);
    }

    @Override
    public Student findById(int id) {
        return studentMapper.selectById(id);
    }

    @Override
    public int edit(Student student) {
        return studentMapper.update(student);
    }

    @Override
    public List<Student> findByPage(int currPage, int pageSize) {
        int fromIndex = (currPage<1)?0:(currPage-1)*pageSize;
        return studentMapper.selectByPage(fromIndex, pageSize);
    }

    @Override
    public boolean login(String username, String password) {
        return studentMapper.selectByNameAndPwd(username,password) !=null;
    }


}
